package com.sjh.lib_app.utils

import android.text.InputFilter
import android.text.Spanned
import java.util.regex.Pattern

/**
 *  一个只允许输入中文的过滤器，用于EditTextView
 * @author : SunJH
 * @data : 2020/9/18
 */
class JustInputChinese :InputFilter{
    override fun filter(
        source: CharSequence?,
        start: Int,
        end: Int,
        dest: Spanned?,
        dstart: Int,
        dend: Int
    ): CharSequence {
        val regex = "[^\\u4E00-\\u9FA5]"
        val str = source.toString()
        val p = Pattern.compile(regex)
        return p.matcher(str).replaceAll("").trim()
    }

}